package com.yl.project.system.files.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yl.framework.aspectj.lang.annotation.Log;
import com.yl.framework.aspectj.lang.enums.BusinessType;
import com.yl.project.system.files.domain.UploadedFiles;
import com.yl.project.system.files.service.IUploadedFilesService;
import com.yl.framework.web.controller.BaseController;
import com.yl.framework.web.domain.AjaxResult;
import com.yl.common.utils.poi.ExcelUtil;
import com.yl.framework.web.page.TableDataInfo;

/**
 * 上传文件信息Controller
 * 
 * @author yl
 * @date 2025-03-10
 */
@Controller
@RequestMapping("/system/files")
public class UploadedFilesController extends BaseController
{
    private String prefix = "system/files";

    @Autowired
    private IUploadedFilesService uploadedFilesService;

    @RequiresPermissions("system:files:view")
    @GetMapping()
    public String files()
    {
        return prefix + "/files";
    }

    /**
     * 查询上传文件信息列表
     */
    @RequiresPermissions("system:files:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UploadedFiles uploadedFiles)
    {
        startPage();
        List<UploadedFiles> list = uploadedFilesService.selectUploadedFilesList(uploadedFiles);
        return getDataTable(list);
    }

    /**
     * 导出上传文件信息列表
     */
    @RequiresPermissions("system:files:export")
    @Log(title = "上传文件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UploadedFiles uploadedFiles)
    {
        List<UploadedFiles> list = uploadedFilesService.selectUploadedFilesList(uploadedFiles);
        ExcelUtil<UploadedFiles> util = new ExcelUtil<UploadedFiles>(UploadedFiles.class);
        return util.exportExcel(list, "files");
    }

    /**
     * 新增上传文件信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存上传文件信息
     */
    @RequiresPermissions("system:files:add")
    @Log(title = "上传文件信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UploadedFiles uploadedFiles)
    {
        return toAjax(uploadedFilesService.insertUploadedFiles(uploadedFiles));
    }

    /**
     * 修改上传文件信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        UploadedFiles uploadedFiles = uploadedFilesService.selectUploadedFilesById(id);
        mmap.put("uploadedFiles", uploadedFiles);
        return prefix + "/edit";
    }

    /**
     * 修改保存上传文件信息
     */
    @RequiresPermissions("system:files:edit")
    @Log(title = "上传文件信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UploadedFiles uploadedFiles)
    {
        return toAjax(uploadedFilesService.updateUploadedFiles(uploadedFiles));
    }

    /**
     * 删除上传文件信息
     */
    @RequiresPermissions("system:files:remove")
    @Log(title = "上传文件信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(uploadedFilesService.deleteUploadedFilesByIds(ids));
    }
}
